package kr.ac.ml.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import kr.ac.ml.action.JSonAction;
import kr.ac.ml.action.ListAction;
import kr.ac.ml.action.MainAction;
import kr.ac.ml.action.WriteAction;
import kr.ac.ml.mvc.Action;




@WebServlet("/main")
public class mainserlvet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		doPost(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String a = request.getParameter("a");
		String content = request.getParameter("content");
		Action action = null;
		
		System.out.println("mainservlet");
		System.out.println("a : " + a);
		System.out.println("content : " + content );
		
		if("write".equals(a)){
			action = new WriteAction();
		}else if("list".equals(a)){
			action = new ListAction();
		}else if("JSon".equals(a)){
			action = new JSonAction();		
		}else{
			action = new MainAction();
		}
		

		
		action.execute(request, response);
		
		System.out.println(request.getAttribute("json"));
		response.setContentType("text/html; charset=utf-8");
		PrintWriter out = response.getWriter();
		out.print(request.getAttribute("json"));
	}

}
